/*************************************************************************
    > File Name: code.c
    > Author: ma6174
    > Mail: ma6174@163.com 
    > Created Time: Thu 20 Feb 2025 12:38:55 PM CST
 ************************************************************************/

#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>                //定义pit_t类型(进程ID的数据类型)
#include<unistd.h>                   //声明geipid()和getppid()函数

void RunChild()
{
	while(1)
	{
		printf("I am child, pid: %d, ppid: %d\n",getpid(),getppid());
		sleep(1);
	}
}

int main()
{
	const int num = 5;              //一次创建5个进程
	
	for(int i = 0; i < num; i++)
	{
		pid_t id = fork();          //创建进程
		if(id==0)
		{
			RunChild();             //调用子进程
		}
		sleep(1);
	}

	//调用父进程
	while(1)
	{
		sleep(1);
		printf("I am parent, pid: %d, ppid: %d\n",getpid(),getppid());
	}

	return 0;
}




